<?php

class ss_cli_command_doctrine extends ss_cli_command {
	protected $cli;
	protected $models;
	
	public function __construct($config,$ss){
		parent::__construct($config,$ss);
		$this->cli= new Doctrine_Cli($config);
	}
	
	public function debug($state=null){
		if(!is_null($state)) Doctrine::debug($state);
		if (Doctrine::debug()) {
			$this->dispatch->output('debugging is on');
		} else {
			$this->dispatch->output('debugging is off');
		}
		return Doctrine::debug();
	}
	
	public function path(){
		return Doctrine::getPath();
	}
	
	public function dump(){
		$this->dispatch->output("\n*** Dumping fixtures ***");
		Doctrine::loadModels(SITE_DOCTRINE_MODELS_PATH);
		return Doctrine::dumpData(SITE_DOCTRINE_DATA_PATH.DIRECTORY_SEPARATOR.'dump'.DIRECTORY_SEPARATOR.'raw_dump.yml');
	}
	
	public function load($append=false){
		$this->dispatch->output("\n*** Loading fixtures ***");
		return Doctrine::loadData(SITE_DOCTRINE_DATA_FIXTURES_PATH, $append);
	}
	
	public function yamlToModel(){
		$this->dispatch->output("\n*** Creating models from schema ***");
		$result=Doctrine::generateModelsFromYaml(SITE_DOCTRINE_SCHEMA_PATH.DIRECTORY_SEPARATOR.'merge'.DIRECTORY_SEPARATOR.'merge.yml', SITE_DOCTRINE_MODELS_PATH, $this->config['generate_models_options']);
		return $result;
	}
	
	public function modelToTable(){
		//$this->loadModels();
		$this->dispatch->output("\n*** Creating tables from models ***");
		$result=Doctrine::createTablesFromModels(SITE_DOCTRINE_MODELS_PATH);
		var_dump($result);
		print(SITE_DOCTRINE_MODELS_PATH);
		return $result;
	}
	
	public function loadModels(){
		if(!is_array($this->models)) $this->models=Doctrine::loadModels(SITE_DOCTRINE_MODELS_PATH);
		return $this->models;
	}
	
	public function modelToSql(){
		return Doctrine::generateSqlFromModels(SITE_DOCTRINE_MODELS_PATH);
	}
	
	public function dropDb(){
		return Doctrine::dropDatabases();
	}
	
	public function createDb(){
		return Doctrine::createDatabases();
	}
}

?>